﻿@using RTW.Model
@model Manage
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
    ViewData["Title"] = "湖北省检察院档案管理系统 - 角色添加";
}
<div class="layui-form layui-form-pane" lay-filter="layuiadmin-form-role" id="layuiadmin-form-role" style="padding: 10px;">
    <form asp-area="Unit" asp-controller="Role" asp-action="RoleFrom" method="post" >
        @if (ViewData["KindsType"].ToString() == "User")
        {
            @if (ViewData["type"].ToString()  != "add")
            {
                @foreach (var item in Model.User)
                {
        <div class="User">
            <div class="layui-form-item">
                <label class="layui-form-label" asp-for="@item.YHZH">用户账户</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-text layui-input" id="YHZH" name="YHZH" lay-verify="required" asp-for="@item.YHZH" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" asp-for="@item.YHMC">姓名</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-text layui-input" id="YHMC" name="YHMC" lay-verify="required" asp-for="@item.YHMC" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" asp-for="@item.YHDH">电话</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-text layui-input" id="YHDH" name="YHDH" asp-for="@item.YHDH" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">身份</label>
                <div class="layui-input-block">
                    <select name="RID" lay-verify="" id="RID" asp-items="@ViewBag.rolelist">
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">部门</label>
                <div class="layui-input-block">
                    <select name="BMID" lay-verify="" id="BMID" asp-for="@item.BMID" asp-items="@ViewBag.deptlist">
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">权限范围</label>
                <div class="layui-input-block">
                    <div class="layui-qxfw">
                        @if (@item.QID == 1)
                        {
                            <input type="checkbox" name="QID" lay-skin="switch" lay-text="查阅|不可查阅" id="QID" value="1" checked>
                        }
                        else
                        {
                            <input type="checkbox" name="QID" lay-skin="switch" lay-text="查阅|不可查阅" id="QID" value="1">
                        }

                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block">
                    <div class="layui-qxfw">
                        @if (int.Parse(@item.YHZT) == 1)
                        {
                            <input type="checkbox" name="YHZT" lay-skin="switch" lay-text="在职|离岗" id="YHZT" value="1" checked>
                        }
                        else
                        {
                            <input type="checkbox" name="YHZT" lay-skin="switch" lay-text="在职|离岗" id="YHZT" value="1">
                        }
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" asp-for="@item.YHBZ">备注</label>
                <div class="layui-input-block">
                    <textarea class="layui-textarea RoleFromTextarea" name="YHBZ" asp-for="@item.YHBZ" ></textarea>
                </div>
            </div>
            <input type="hidden" asp-for="@item.TJSJ" name="TJSJ" />
            <input type="hidden" asp-for="@item.YHID" name="YHID" />
            <input type="hidden" value="@ViewData["UserRoleID"]" name="ID" />
        </div>
                }
            }
            else
            {
    <div class="User">
        <div class="layui-form-item">
            <label class="layui-form-label">用户账户</label>
            <div class="layui-input-block">
                <input type="text" class="layui-text layui-input" name="YHZH" id="YHZH" lay-verify="required" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">姓名</label>
            <div class="layui-input-block">
                <input type="text" class="layui-text layui-input" name="YHMC" id="YHMC" lay-verify="required" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">电话</label>
            <div class="layui-input-block">
                <input type="text" class="layui-text layui-input" name="YHDH" id="YHDH"  />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">身份</label>
            <div class="layui-input-block">
                <select name="RID" lay-verify="" id="RID" asp-items="@ViewBag.rolelist">
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">部门</label>
            <div class="layui-input-block">
                <select name="BMID" lay-verify="" id="BMID" asp-items="@ViewBag.deptlist">
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">权限范围</label>
            <div class="layui-input-block">
                <div class="layui-qxfw">
                    <input type="checkbox" name="QID" lay-skin="switch" lay-text="可查阅|不可查阅" id="QID" checked value="1">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <div class="layui-qxfw">
                    <input type="checkbox" name="YHZT" lay-skin="switch" lay-text="在职|离岗" id="YHZT" checked value="1">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" >备注</label>
            <div class="layui-input-block">
                <textarea class="layui-textarea"  name="YHBZ"></textarea>
            </div>
        </div>
    </div>

            }
        }
        else if (ViewData["KindsType"].ToString() == "Dept")
        {
            @if (ViewData["type"].ToString()  != "add")
            {
                @foreach (var item in Model.Dept)
                {
            <div class="Dept">
                <div class="layui-form-item">
                    <label class="layui-form-label" asp-for="@item.BMMC">名称</label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-text layui-input" id="BMMC" name="BMMC" lay-verify="required" asp-for="@item.BMMC" />
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" asp-for="@item.BMDM">代码</label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-text layui-input" id="BMDM" name="BMDM" lay-verify="required" asp-for="@item.BMDM" />
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" asp-for="@item.BMPY">拼音码</label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-text layui-input" id="BMPY" name="BMPY" lay-verify="required" asp-for="@item.BMPY" />
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" asp-for="@item.BMBH">编号</label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-text layui-input" id="BMBH" name="BMBH" lay-verify="required" asp-for="@item.BMBH" />
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" asp-for="@item.BMBZ">备注</label>
                    <div class="layui-input-block">
                        <textarea class="layui-textarea RoleFromTextarea" asp-for="@item.BMBZ" name="BMBZ"></textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <div class="layui-qxfw">
                            @if (@item.BMZT == "1")
                            {
                                <input type="checkbox" name="BMZT" lay-skin="switch" lay-text="可用|停用" id="BMZT" value="1" checked>
                            }
                            else
                            {
                                <input type="checkbox" name="BMZT" lay-skin="switch" lay-text="可用|停用" id="BMZT" value="1">
                            }
                        </div>
                    </div>
                </div>
                <input type="hidden" id="BMID" asp-for="@item.BMID" name="BMID" />
                <input type="hidden" id="BMTJSJ" asp-for="@item.BMTJSJ" name="BMTJSJ" />
            </div>
                }
            }
            else
            {
                <div class="Dept">
                    <div class="layui-form-item">
                        <label class="layui-form-label">名称</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-text layui-input" id="BMMC" name="BMMC" lay-verify="required" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">代码</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-text layui-input" id="BMDM" name="BMDM" lay-verify="required" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">拼音码</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-text layui-input" id="BMPY" name="BMPY" lay-verify="required" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">编号</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-text layui-input" id="BMBH" name="BMBH" lay-verify="required" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">备注</label>
                        <div class="layui-input-block">
                            <textarea class="layui-textarea RoleFromTextarea" name="BMBZ"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-block">
                            <div class="layui-qxfw">
                                <input type="checkbox" name="BMZT" lay-skin="switch" lay-text="可用|停用"  id="BMZT" checked value="1">
                            </div>
                        </div>
                    </div>
                </div>
            }
        }
        else if (ViewData["KindsType"].ToString() == "Role")
        {
            @if (ViewData["type"].ToString()  != "add")
            {
                @foreach (var item in Model.Role)
                {
    <div class="Role">
        <div class="layui-form-item">
            <label class="layui-form-label" asp-for="@item.RMC">角色</label>
            <div class="layui-input-block">
                <input type="text" class="layui-text layui-input" id="RMC" lay-verify="required" asp-for="@item.RMC" name="RMC" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" asp-for="@item.RMC">角色代码</label>
            <div class="layui-input-block">
                <input type="text" class="layui-text layui-input" id="RDM" lay-verify="required" asp-for="@item.RDM" name="RDM" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">阅卷权限</label>
            <div class="layui-input-block">
                <select name="RJB" lay-verify="" id="@item.RJB" asp-for="@item.RJB">
                    <option value="1">个人</option>
                    <option value="2">全院</option>
                    <option value="3">部门</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" asp-for="@item.RBZ">备注</label>
            <div class="layui-input-block">
                <textarea class="layui-textarea" asp-for="@item.RBZ" name="RBZ"></textarea>
            </div>
        </div>
        <input type="hidden" asp-for="@item.RID" name="RID" />
    </div>
                }
            }
            else
            {
                <div class="Role">
                    <div class="layui-form-item">
                        <label class="layui-form-label">角色名称</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-text layui-input" id="RMC" lay-verify="required" name="RMC" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">角色代码</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-text layui-input" id="RDM"  name="RDM" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">阅卷权限</label>
                        <div class="layui-input-block">
                            <select name="RJB" lay-verify="">
                                <option value="1">个人</option>
                                <option value="2">全院</option>
                                <option value="3">部门</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">备注</label>
                        <div class="layui-input-block">
                            <textarea class="layui-textarea RoleFromTextarea" name="RBZ"></textarea>
                        </div>
                    </div>
                </div>
            }
        }

        <div class="layui-form-item  layui-hide">
            <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit" value="确认添加">
            <input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit" value="确认编辑">
        </div>
        <input type="hidden" id="dwid" name="DWID" value="@(ViewData["dwid"])" />
        <input type="hidden" id="type" name="type" value="@(ViewData["type"])" />
        <input type="hidden" id="KindsType" name="KindsType" value="@(ViewData["KindsType"])" />
    </form>
</div>

@section scripts{
    <script>
        layui.config({
            base: '../../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'form', 'layer'], function () {
            var $ = layui.$
                , form = layui.form, layer = layui.layer;


            $("#RID").val("@(ViewData["CheackRoleFrom"])");
            form.render('select')
            //监听提交submit(layuiadmin-app-form-submit)
            form.on('submit(layuiadmin-app-form-submit)', function (data) {
                  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                var dataform = $('form').serialize();
                var type = $("#type").val();
                var KindsType = $("#KindsType").val();
                var field = "";
                if (KindsType == "User") {
                    field = "n=" + data.field; //获取提交的字段
                }
                else if (KindsType == "Dept") {
                    field="dept="+ data.field; //获取提交的字段
                } else if (KindsType=="Role") {
                    field="role="+ data.field; //获取提交的字段
                }
                $.ajax({
                    type: "POST",
                    url: "/Unit/Role/RoleFrom?type=" + type+"&KindsType="+KindsType,
                    async: true,
                    data: data.field,
                    dataType: "json",
                    success: function (res) {
                        if (res.code == '0') {
                            parent.layer.close(index); //再执行关闭
                        }
                        res.success ? top.layer.msg(res.msg, { icon: 6, times: 2000 }) : top.layer.msg(res.msg, { icon: 5, times: 2000 });
                    },
                    error: function (data) {

                    }
                });
                return false;
            });
            form.on('submit(layuiadmin-app-form-edit)', function (data) {
                var field = data.field; //获取提交的字段
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                var dataform = $('form').serialize();
                var type = $("#type").text();
                ;                //提交 Ajax 成功后，关闭当前弹层并重载表格
                $.ajax({
                    type: "POST",
                    url: "/Unit/Role/RoleFrom?type=" + type+"&KindsType="+KindsType,
                    async: true,
                    data: field,
                    success: function (res) {
                        if (res.code == '0') {
                            parent.layer.close(index); //再执行关闭
                        }
                        res.success ? top.layer.msg(res.msg, { icon: 6, times: 2000 }) : top.layer.msg(res.msg, { icon: 5, times: 2000 });
                    },
                    error: function (data) {

                    }
                });
                return false;
            });
        })
    </script>
}